<template>
	  <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
    <h3 class="title">忘记密码</h3>
    
      <router-link to="/login" class="account-right" style="" >返回登录</router-link>

 
      <el-form-item prop="account">
        <el-input type="number" v-model="ruleForm2.account" auto-complete="off" placeholder="手机号"></el-input>
      </el-form-item>

    <el-form-item prop="verificationCode">
      <el-input type="text" style="width:69%" v-model="ruleForm2.verificationCode" auto-complete="off" placeholder="验证码"></el-input>
      <button class="account-pb-bt" @click="codesb" type="button">{{codehtml}}</button>
    </el-form-item>
    <el-form-item prop="checkPass">
      <el-input type="password" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item prop="checkPass1">
      <el-input type="password" v-model="ruleForm2.checkPass1" auto-complete="off" placeholder="确认密码"></el-input>
    </el-form-item>
    <!-- <el-checkbox v-model="checked" checked class="remember">记住密码</el-checkbox> -->
      <!-- <router-link to="/monitor"  class="transition-box">忘记密码</router-link> -->
    <el-form-item style="width:100%;">
      <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">提交</el-button>
    </el-form-item>
 
  </el-form>
</template>

<script>
  import { reset_pass,send_reset_pass_code } from '../../api/api';
  //import NProgress from 'nprogress'
  export default {
    data() {
      return {
        logining: false,
        codes: 60,
        codehtml: "获取验证码",
        ruleForm2: {
          account: "",
          checkPass: "",
          checkPass1: "",
          verificationCode: "",
      
        },
        rules2: {
          account: [{
              required: true,
              message: "请输入账号",
              trigger: "blur"
            },
            {
              pattern: /^((1[358][0-9])|(14[57])|(17[03678])|(19[7]))\d{8}$/,
              message: "请填写正确手机号码",
              trigger: "blur"
            }
            //{ validator: validaePass }
          ],
          verificationCode:[{
              required: true,
              message: "请输入验证码",
              trigger: "blur"
            }],
          checkPass: [{
              required: true,
              message: "请输入密码",
              trigger: "blur"
            },
            {
              pattern: /^[a-zA-Z0-9]{6,18}$/,
              message: "密码由6-10位组成",
              trigger: "blur"
            }
            //{ validator: validaePass2 }
          ],
          checkPass1: [{
              required: true,
              message: "请输入密码",
              trigger: "blur"
            },
            {
              pattern: /^[a-zA-Z0-9]{6,18}$/,
              message: "密码由6-10位组成",
              trigger: "blur"
            }
          ],
          checkemail: [{
            required: true,
            message: "请输入邮箱",
            trigger: "blur"
          }],
          companyName: [{
            required: true,
            message: "请输入组织名",
            trigger: "blur"
          }],
          companyLevel: [{
            required: true,
            message: "请输入职务",
            trigger: "blur"
          }],
          verificationCode: [{
            required: true,
            message: "请输入验证码",
            trigger: "blur"
          }]
        },
        checked: true
      };
    },
    methods: {
      codesb() {
        var params = {
          phone: this.ruleForm2.account
        };
        if (this.codes < 60) {
          console.log(this.codes)
          return false;
        }


        send_reset_pass_code(params).then(data => {
          //NProgress.done();
          let {
            code,
            user,
            message
          } = data;
          if (code !== 0) {
            this.$message({
              message: message,
              type: "error"
            });
          } else {
            let t = setInterval(() => {
              this.codehtml = this.codes-- + "s";
              if (this.codes == 0) {
                clearInterval(t);
                this.codes = 60;
                this.codehtml = '获取验证码';
              }
            }, 1000);
            this.$message({
              message: '验证码已发送',
              type: "succeed"
            });
          }
        });
      },
      handleReset2() {
        this.$refs.ruleForm2.resetFields();
      },
      handleSubmit2(ev) {
        var _this = this;
        this.$refs.ruleForm2.validate(valid => {
          if (valid) {
            //_this.$router.replace('/table');
            this.logining = true;
            //NProgress.start();
            var loginParams = {
              phone: this.ruleForm2.account,
              password: this.ruleForm2.checkPass,
              repassword: this.ruleForm2.checkPass1,
              verificationCode: this.ruleForm2.verificationCode
            };
            reset_pass(loginParams).then(data => {
              this.logining = false;
              //NProgress.done();
              let {
                code,
                user,
                message
              } = data;
              if (code !== 0) {
                this.$message({
                  message: message,
                  type: "error"
                });
              } else {
                this.$message({
                  message: '修改密码成功',
                  type: "succeed"
                });
                
        this.$router.push({ path: "/login" });
              }
            });
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      }
    }
  };

</script>

<style lang="scss" scoped>
.transition-box{
  float:right;
}
  .login-container {
    /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    .title {
      margin: 0px auto 40px auto;
      text-align: center;
      color: #505458;
    }
    .remember {
      margin: 0px 0px 35px 0px;
    }
  }
</style>